package net.huashitong.ssydt.provider.gexin.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.huashitong.ssydt.provider.annotations.LoginRequired;
import net.huashitong.ssydt.provider.gexin.service.SsPushGetuiService;
import net.huashitong.ssydt.provider.web.model.Result;
import net.huashitong.ssydt.provider.web.utils.ResultUtils;
import net.huashitong.ssydt.security.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author <a href="mailto:yhy23456@163.com">huiyang.yu</a>
 * @since 2017.10.09
 */
@Api(value = "/api/getui", tags = {"个推相关"})
@RestController
@RequestMapping("/api/getui")
public class ApiGetuiPushController {

    private SsPushGetuiService ssPushGetuiService;

    @Autowired
    public ApiGetuiPushController(SsPushGetuiService ssPushGetuiService) {
        this.ssPushGetuiService = ssPushGetuiService;
    }

    @ApiOperation(value = "注册clientid", notes = "注册clientid", produces = MediaType.APPLICATION_JSON_VALUE)
    @LoginRequired
    @PostMapping("/clientid/{clientid}")
    public Result<String> postRegister(@ApiParam(name = "clientid", required = true)
                                       @PathVariable String clientid) {
        String userId = UserUtils.getUserId();
        ssPushGetuiService.register(userId, clientid);
        return ResultUtils.getSuccessResults();
    }


    @ApiOperation(value = "注销clientid", notes = "注销clientid", produces = MediaType.APPLICATION_JSON_VALUE)
    @LoginRequired
    @DeleteMapping("/clientid")
    public Result<String> deleteCancel() {
        String userId = UserUtils.getUserId();
        ssPushGetuiService.deleteCancel(userId);
        return ResultUtils.getSuccessResults();
    }

}
